package com.bobi.tfca.controller.audit;

import com.bobi.tfca.model.entity.MemberEntity;
import com.bobi.tfca.model.pojo.R;
import com.bobi.tfca.model.vo.ArticleVO;
import com.bobi.tfca.model.vo.AuditVO;
import com.bobi.tfca.service.AuditService;
import com.bobi.tfca.service.MemberService;
import com.bobi.tfca.web.annotation.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 李文发
 * @date 2024/4/20
 */
@RestController
@RequestMapping("/audit")
@Api(tags = "审核接口")
@Slf4j
public class AuditController {

    @Autowired
    private AuditService auditService;

    @ApiOperation(value = "查询所有入会申请")
    @GetMapping("/findAllEntryApply")
    public R<List<AuditVO>> findAllEntryApply() {
        List<AuditVO> list = auditService.findAllEntryApply();
        return R.data(list);
    }

    @ApiOperation(value = "查询所有退会申请")
    @GetMapping("/findAllExitApply")
    public R<List<AuditVO>> findAllExitApply() {
        List<AuditVO> list = auditService.findAllExitApply();
        return R.data(list);
    }

    @ApiOperation(value = "通过审核")
    @PostMapping("/passAudit/{auditId}")
    @ApiImplicitParams({@ApiImplicitParam(name = "auditId", value = "审核的id"),
            @ApiImplicitParam(name = "member", value = "审核人")})
    public R<String> passAudit(@PathVariable("auditId") Integer auditId, @CurrentUser MemberEntity member) {
        Boolean success = auditService.passAudit(auditId, member);
        return success ? R.data("通过") : R.error("操作失败");
    }

    @ApiOperation(value = "拒绝审核")
    @PostMapping("/refuseAudit/{auditId}")
    @ApiImplicitParams({@ApiImplicitParam(name = "auditId", value = "审核的id"),
            @ApiImplicitParam(name = "member", value = "审核人")})
    public R<String> refuseAudit(@PathVariable("auditId") Integer auditId, @CurrentUser MemberEntity member) {
        Boolean success = auditService.refuseAudit(auditId, member);
        return success ? R.data("拒绝") : R.error("操作失败");
    }

    @ApiOperation(value = "申请退出协会")
    @PostMapping("/applyQuitAss")
    @ApiImplicitParams({@ApiImplicitParam(name = "leaveWords", value = "留言"),
            @ApiImplicitParam(name = "member", value = "申请人")})
    public R<String> applyQuitAss(@RequestBody String leaveWords, @CurrentUser MemberEntity member) {
        Boolean success = auditService.applyQuitAss(leaveWords, member);
        return R.data("操作成功");
    }
}
